package com.lil.shiro.controller;

import com.lil.shiro.exception.BusinessException;
import com.lil.shiro.model.User;
import com.lil.shiro.result.ApiResponse;
import com.lil.shiro.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @GetMapping(value = "/user/login")
    public String login() {
        return "登录页";
    }

    @PostMapping(value = "/user/login")
    public ApiResponse login(String userId, String password)throws BusinessException {
        System.out.println("login()");
        ApiResponse apiResponse = loginService.login(userId, password);
        return apiResponse;
    }

    @GetMapping(value = "/index")
    public String index() {
        return "主页";
    }

    @GetMapping(value = "/logout")
    public String logout() {
        return "退出";
    }

    @GetMapping("/403")
    public String unauthorizedRole() {
        return "没有权限";
    }
}